<template>
	<view class='content'>
		<view class="logo">
			<image class='logo_img' src="../../static/admin_logo.png" mode="widthFix"></image>
			
		</view>
		<view class="login_title">
			员工登录
		</view>
		
		<view class="input_wrap">
			<view class="input_items">
				<u--input
				    placeholder="请输入账号"
					class='input'
				    v-model="mobile"
				  ></u--input>
			</view>
			<view class="input_items">
				<u--input
					type='password'
				    placeholder="请输入密码"
					class='input'
				   
				    v-model="password"
				  ></u--input>
			</view>
			
			<u-button class='btn' text="登录" type="primary" @click='login'></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile: '',
				password: ''
			}
		},
		methods: {
			login(){
				var _this = this
				uni.request({
					url: 'http://www.yndzfl.cn/wxsite/Staff/staffLogin',
					method: 'POST',
					header:{
						"Content-Type" : "application/x-www-form-urlencoded"
					},
					data: {
						openid: uni.getStorageSync('OPENID'),
						mobile: _this.mobile,
						password: _this.password
					},
					success(res) {
						console.log(res)
						if(res.data.code == 1){
							uni.showToast({
								title: '登录成功',
								icon: 'none'
							})
							uni.setStorageSync("token",res.data.data.token);
							setTimeout(function(){
								uni.reLaunch({
									url: '/pages/admin/index'
								})
							},500)
						}else if(res.data.code == -1){
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
							uni.reLaunch({
								url: '/pages/home/home?type=2'
							})
						}else if(res.data.code == 408){
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
							uni.reLaunch({
								url: '/pages/admin/login'
							})
						}else{
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
						
					}
				})
			}
		}
	}
</script>

<style scoped>
.logo{
	height: 120px;
	line-height: 120px;
	text-align: center;
	display: flex;
	align-items: flex-end;
	justify-content: center;
}
.logo_img{
	width: 70px;
	height: 70px;
}
.login_title{
	text-align: center;
	margin-top: 10px;
}
.input_wrap{
	padding: 10px 20px;
	box-sizing: border-box;
}
.input_items{
	margin-top: 20px;
}
.input{
	background: #fff;
	height: 35px;
}
.btn{
	height: 40px;
	margin-top: 40px;
}
</style>
